<?php
/**
 * RedCross Application
 *
 * @copyright Copyright (c) 2010, Kristian Stokke Tryggestad, Rune Vikestad, Andreas Flaten Wist, Simen Nicolai Echholt, Ole Henrik Jahren
 */

/**
 * Random global functions. Class for putting stuff that would be global,
 * but that Zend with it's object-orientedness can not address when is.
 *
 * @category RedCross
 * @package RedCross
 */

class RedCross_Global
{

	/**
	 * Function for comparing sort_order two shift roles.
	 *
	 * @param $r1 Shift role 1
	 * @param $r2 Shift role 2
	 * @return int Less than, equal or greater than zero , if the
	 *	sort_order of $r1 is less than, equal or greater than the
	 *	sort_order of $r2.
	 */
	public static function shift_role_sort_cmp($r1, $r2)
	{
		return (int)$r1['Role']['sort_order'] -
			(int)$r2['Role']['sort_order'];
		//return (int)$r1->Role->sort_order -
		//	(int)$r2->Role->sort_order;
	}

	/**
	 * Function for comparing start time of shifts
	 *
	 * @param $s1 Shift 1
	 * @param $s2 Shift 2
	 * @return int Less than, equal or greater than zero , if the
	 *	start time of $s1 is less than, equal or greater than the
	 *	start time of $s2.
	 */
	public static function shift_sort_cmp($s1, $s2)
	{
		$t1 = new RedCross_Date($s1['from_date'], RedCross_Date::DB_FMT);
		$t2 = new RedCross_Date($s2['from_date'], RedCross_Date::DB_FMT);
		return $t1->getTimestamp() - $t2->getTimestamp();
	}

	/**
	 * @param $sr The shift_role to hash
	 * @return Hash of the shift_role
	 */
	public static function shift_role_hash(
			RedCross_Gateway_Base_ShiftRole $sr)
	{
		return sha1($sr->notification_sent_time .
			':' . $sr->id . ':' . $sr->member_id);
	}
}
